<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>基础表单</title>
    <link rel="stylesheet" href="__LIBS__/layui/css/layui.css"/>
    <link rel="stylesheet" href="__MODULE__/admin.css?v=317"/>
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .layui-upload-img {
            width: 200px;
            min-height: 120px;
            height: auto;
            margin: 0 10px 10px 0;
        }

    </style>
</head>
<body>
<!-- 加载动画 -->
<div class="page-loading">
    <div class="ball-loader">
        <span></span><span></span><span></span><span></span>
    </div>
</div>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">添加分类 </div>
        <div class="layui-card-body">
            <form class="layui-form" id="formBasForm" lay-filter="formBasForm" style="max-width: 960px;">
                <input type="hidden" name="id" value="{$item['id']?$item['id']:''}">
                <input type="hidden" name="state" value="{$item['status']?$item['state']:''}">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-required">名称:</label>
                    <div class="layui-input-block">
                        <input name="flname"  class="layui-input" required lay-verify="required" value="{$item['flname']?$item['flname']:''}"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label ">序号:</label>
                    <div class="layui-input-block">
                        <input name="xh"  class="layui-input" value="{$item['xh']?$item['xh']:''}"/>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text" >
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block text-center">
                        <button class="layui-btn" lay-filter="formBasSubmit" lay-submit>&emsp;提交&emsp;</button>
                        <button ew-event="closeThisTabs" type="button" class="layui-btn layui-btn-primary">&emsp;关闭&emsp;</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- js部分 -->
<script type="text/javascript" src="__LIBS__/layui/layui.js"></script>
<script type="text/javascript" src="__NJS__/common.js?v=317"></script>
<script>
    layui.use(['layer', 'form', 'laydate','upload','admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var upload = layui.upload;
        var admin = layui.admin;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: "{:url('admin/Upload/uploadLocality')}" //改成您自己的上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                console.log(res)
                //如果上传失败
                if(res.code == 0){
                    $("input[name='thumb']").val(res.data);
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });
        /* 渲染laydate */
        laydate.render({
            elem: '#formBasDateSel',
            trigger: 'click',
            range: true
        });

        /* 监听表单提交 */
        form.on('submit(formBasSubmit)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('fenlei_add')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    //console.log(res)
                    if (res.code == 0) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1})
                        setTimeout(function () {
                            admin.closeThisTabs();
                        }, 1000);
                    } else {
                        $(".layui-btn").removeClass('layui-disabled').removeAttr('disabled');
                        wk.error(res.msg);
                        return false;
                    }
                }
            })
        });
    });
</script>
</body>
</html>